import React from "react";
import {connect} from "react-redux"
import {Button} from "antd-mobile"

class Counter extends React.Component {

  goHomePage = () =>{
    this.props.history.push("/")
  }

  render() {
    console.log(this.props.location.state)
    return (
      <div>
        <h1>恭喜你，获得了{this.props.location.state.score}分</h1>
        <Button type="primary" onClick={this.goHomePage}>回到首页</Button>
      </div>
    );
  }
}



//将state映射到props函数
const mapStateToProps = (state) => {
  return {
    value: state.num,
  };
};

//将修改state数据的方法映射到props
const mapDispatchToProps = (dispatch) => {
  return {
    onAddClick: () =>
      dispatch({
        type: "add",
      }),
    onAddClick5: () => dispatch({ type: "addNum", num: 5 }),
  };
};

//将上面的这两个方法，将数据仓库的state和修改state的方法映射到组件上，形成新的组件
const Result = connect(mapStateToProps, mapDispatchToProps)(Counter);

export default Result
